<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>竞技之星</title>
<link href="${path }/resource/css/scale-css.css" type="text/css" rel="stylesheet" />
<!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
<script type="text/javascript" src="${path }/resource/js/scale.js"></script>
<style type="text/css">
	@font-face {
		font-farmily: fzlthjw;
		src: url(${path }/resource/images/jjstar/fzlthjw.ttf);
	}
	.czbg{
		background: url(${path }/resource/images/jjstar/充值.jpg) no-repeat;
		background-size:100% 100%;
		background-position:center;
		width: 100%;
		height: 100%;
		color: rgb(169,203,188);
		font-family: fzlthjw;
		font-size: 14px;
	}
	.czbtn{
		width: 30%;
		padding-top: 5px;
	}
	.czform{
		background: url(${path }/resource/images/jjstar/czk.jpg) no-repeat;
		background-size:100% 100%;
		background-position:center;
		width: 30%;
		padding-top: 5px;
	}
</style>
</head>

<body>
	<div class="div-container czbg">
		<div style="height: 15%;">
			<div class="div-title"></div><br>
<!-- 			<div class="sub-title" style="margin-top: -290px;margin-left: 260px;"></div> -->
		</div>
<!-- 		<div class="div-bg div-line-bg5"></div> -->
		<div style="height: 20px;">
			<table style="width:100%"><tr><td style="width:50%"></td>
				<td style="width:25%">帐号：${gameUser.userid }</td>
				<td style="width:25%">余额：${gameUser.diamondnum }</td>
			</tr></table>
		</div>
<!-- 		<div class="div-content" style="margin-top: -1px;">购买俱乐部</div> -->
		<div class="div-bg" style="height:2px;margin-top: -1px;"></div>
		<div class="czdetail">
			<div class="czbtn">
				<a><img alt="充值" src="${path }/resource/images/jjstar/cz.png"></a>
			</div>
			<div class="czform">
			</div>
		</div>
		<c:if test="${clubs ne null }">
			<c:forEach var="club" items="${clubs}" varStatus="status">
				<div class="div-content1">
					<input  name="vip" type="radio" value="${club.money}-${club.id}" onclick="getRechargeMoney(this.value)" id="club"
						<c:if test='${status.count eq 1}'>checked='checked'</c:if>>&nbsp;
					${club.description}<span class="span-text1">${club.money}元
					<%-- <c:if test="${!empty club.giveNum}">
						(赠送${club.giveNum}钻石)
					</c:if> --%>
					</span>
				</div>
				<c:if test="${status.count ne clubs.size()}">
					<div class="div-line-black" style="margin-top: -1px;"></div>
				</c:if>
			</c:forEach>
		</c:if>

		<div class="div-bg div-line-bg5"></div>
		<div class="div-content" style="margin-top: -1px;">钻石充值</div>
		<div class="div-bg div-line-bg2" style="margin-top: -1px;"></div>

		<c:if test="${diamonds ne null }">
			<c:forEach var="diamond" items="${diamonds}" varStatus="status">
				<div class="div-content1">
					<input class="radio-box" name="vip" type="radio"
						value="${diamond.money}-${diamond.id}"
						onclick="getRechargeMoney(this.value)"> &nbsp;
					${diamond.num}钻石 <span class="span-text1">${diamond.money}元
					<c:if test="${!empty diamond.giveNum}">
						(赠送${diamond.giveNum}钻石)
					</c:if>
					</span>
				</div>
				<c:if test="${status.count ne diamonds.size()}">
					<div class="div-line-black" style="margin-top: -1px;"></div>
				</c:if>
			</c:forEach>
		</c:if>

		<div class="div-line20"></div>
		<div class="div-content" style="margin-top: -1px;" onclick="toggleUser()">账户信息</div>
		<div class="div-bg div-line-bg2" style="margin-top: -1px;"></div>
		<div class="div-content1" style="margin-top: -1px;">
			请输入游戏ID:<input class="input-text" type="text" id="gameId" /><br>
			<br>
			<br> <span id="getClubName"> 请输入俱乐部名称:<input
				class="input-text" type="text" id="clubName" /><br>
			<br>
			<br>
			</span> 请确认金额: <span class="span-text1" id="rechargeMoney">0</span>元
		</div>
		
		<div class="div-content" style="margin-top: -1px;" onclick="crossTransfer()">跨平台转账
		<span class="fa fa-chevron-right"></span>
		</div>
		
		<!--<div class="div-content" style="margin-top: -1px;" onclick="toggleDiamond()">钻石转账 -->
		<!--<span class="fa fa-chevron-down" id="diamondDownIcon"></span>
		<span class="fa fa-chevron-up" id="diamondUpIcon" style="display: none;"></span>
		</div>-->
		<div class="div-bg div-line-bg2" style="margin-top: -1px;"></div>
		<div class="div-content1" style="margin-top: -1px; display: none;" id="diamondOut">
			<span> 当前用户ID:<span id="currentId">${gameUser.userid }</span><br><br><br></span>
			<span> 当前钻石数量:<span id="diamondNum">${gameUser.diamondnum }</span><br><br><br></span>
			<span> 转账用户ID:<input class="input-text" type="text" id="receiveId"/><br><br><br></span>
			 <span> 转出钻石数量:<input class="input-text" type="text" id="outNum" /><br><br><br></span>
		</div>
		
		<div class="div-bg div-line-bg120">
			<span class="div-btn div-font-size" onclick="toPay()" id="toPay">使用支付宝支付</span>
			<span class="div-btn div-font-size" style="display:none;" onclick="transferDiamond()" id="outDiamond">转账</span>
		</div>
	</div>
	<div id="wxDiv" class="wx-tip">
		<img id="wxImg" src="${path }/resource/images/weixin-tip.png"></img>
	</div>
</body>
<script type="text/javascript">
var receiveId;//转账接受人ID
var outNum;//钻石转出数量
var gameId;//充值游戏玩家ID
var clubName;//俱乐部名称
var rechargeId;//充值项目ID
var currentId = $("#currentId").text();//当前登录用户的ID
var diamondNum = $("#diamondNum").text();//当前用户钻石数量
var rechargeMoney = $("#rechargeMoney").text();//转账金额

$().ready(function(){
	$("[name='vip']").each(function(){
		if($(this).get(0).checked){
			var str= $(this).val().split("-");
			$("#rechargeMoney").text(str[0]);
		}
	});
});
function getRechargeMoney(v){
	var str = v.split("-");
	$("#rechargeMoney").text(str[0]);
	if($("#club").get(0).checked){
		$("#getClubName").show();
	}else{
		$("#getClubName").hide();
	}
}
//支付
function toPay(){
	gameId = $("#gameId").val();
	clubName = $("#clubName").val().trim();
	$("[name='vip']").each(function(){
		if($(this).get(0).checked){
			var str= $(this).val().split("-");
			rechargeId = str[1];
		}
	});
	if(gameId==""||!gameId.match(/^\d+$/)){
		alert("游戏ID不合法！");
		return false;
	}
	if(rechargeMoney==""||rechargeMoney==null){
		alert("充值金额不能为空！");
		return false;
	}
	/* if(!$("#clubName").is(":hidden")){
		if(clubName==""||clubName==null){
			alert("俱乐部名称不能为空！");
			return false;
		}else if(!clubName.match(/^[\u4e00-\u9fa5A-Za-z0-9-_]*$/)){
			alert("俱乐部名称不合法！");
			return false;
		}
	} */
	getGameUser(gameId,1);
}


$(window).on("load", function() {
    var winHeight = $(window).height();
    var winWidth = $(window).width();
    function is_weixin() {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            return true;
        } else {
            return false;
        }
    }
    var isWeixin = is_weixin();
    if (isWeixin) {
    	 $("#wxImg").css("height", winHeight+220);
    	 $("#wxImg").css("width", winWidth);
         $("#wxDiv").show();
    }
});

function transferDiamond(){
	receiveId = $("#receiveId").val();
	outNum = $("#outNum").val().trim();
	if(receiveId==null||receiveId==""||!receiveId.match(/^\d+$/)){
		alert("接收人ID不合法！");
	}else if(outNum.trim()==null||outNum==""||outNum==0){
		alert("转出钻石不能为空！");
	}else if(!outNum.match(/^\d+$/)){
		alert("钻石数量只能为数字");
	}else if(parseInt(outNum)>parseInt(diamondNum)){
		alert("钻石数量不足,赶快充值吧！");
	}else if(parseInt(diamondNum)<=0){
		alert("钻石余额不足,赶快充值吧！");
	}else if(receiveId==currentId){
		alert("无法自己给自己转账！");
	}else{
		 if(confirm("确定要转账吗")){
			getGameUser(receiveId,2);
		 }
	}
}

//判断用户是否存在
function getGameUser(gameId,type){
	if(gameId!=null&&gameId!=""){
		$.ajax({
		    type: "post",
		    url: "${path}/client/getGameUser",     
		    data: {"gameId":gameId},    
		    success: function(data) {
		    	if(data.code=='true'){//用户存在
		    		if(type==1){//充值
		    			if(rechargeId == '1' && data.msg=='fullClubs') {
		    				alert("加入俱乐部数量已达上限，无法创建俱乐部");
		    			} else {
		    				location.href = "${path}/client/toPay?rechargeId="+rechargeId+"&gameId="+gameId+"&clubName="+clubName;
		    			}
		    		}
		    		if(type==2){//转账
		    			outDiamond();
		    		}
		    	} else{
		    		alert("用户ID不存在！");
		    	}
		    },
		 });
	}
}

//进入钻石转账
function outDiamond(){
	$.ajax({
	    type: "post",
	    url: "${path}/client/outDiamond",     
	    data: {"receiveId":receiveId,
	    		"outNum":outNum},    
	    success: function(data) {
	    	if(data.code=='true'){
	    		alert("转账成功！");
	    		window.location.reload();//刷新当前页面.
	    	}else{
	    		alert("转账失败，请刷新页面后重试！");
	    	}
	    },
	 });
}

function toggleDiamond(){
	if($("#diamondOut").is(":hidden")){
		$("#diamondOut").show();
		$("#diamondDownIcon").hide();
		$("#diamondUpIcon").show();
		$("#outDiamond").show();
		$("#toPay").hide();
	}else{
		$("#diamondOut").hide();
		$("#diamondDownIcon").show();
		$("#diamondUpIcon").hide();
		$("#outDiamond").hide();
		$("#toPay").show();
	}
}

function crossTransfer(){
	window.open('${path}/transfer/toTransfer', '_self', '');
}

function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
}
var isPC = false;
$().ready(function(){
	isPC = IsPC();
	if(IsPC()) {
		var hig = document.documentElement.clientHeight;
		$(".czbg").css("background-size", "auto 100%");
		$(".czdetail").css("width", (hig*72)/128);
		$(".azxz").css("margin-top", "0");
		$("body").css("background-color", "#17181D");
	}
});
</script>
</html>